<?php

namespace App\Repositories\Order;

use Illuminate\Support\Facades\DB;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Repositories\Order\OrderGoodsRepository;
use App\Models\Order\OrderGoods;
use App\Validators\Order\OrderGoodsValidator;

/**
 * Class OrderGoodsRepositoryEloquent
 * @package namespace App\Repositories\Order;
 */
class OrderGoodsRepositoryEloquent extends BaseRepository implements OrderGoodsRepository
{
    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return OrderGoods::class;
    }

    /**
    * Specify Validator class name
    *
    * @return mixed
    */
    public function validator()
    {

        return OrderGoodsValidator::class;
    }


    /**
     * Boot up the repository, pushing criteria
     */
    public function boot()
    {
        $this->pushCriteria(app(RequestCriteria::class));
    }

    /**
     * @author yangzhic
     * @param $data
     * @return bool
     * @throws \Prettus\Repository\Exceptions\RepositoryException
     */
    public function batchInsert($data){
        return DB::table($this->makeModel()->getTable())->insert($data);
    }

    /**
     * @author yangzhic
     * @return array
     * @throws \Prettus\Repository\Exceptions\RepositoryException
     */
    public function getOrderGoodsColumns(){
        $columns = Schema::getColumnListing($this->makeModel()->getTable());
        return $columns;
    }

    public function getGoodsList($orderId){
        return $this->findWhere(['order_id'=>$orderId])->toArray();
    }
}
